package com.mihe.core.config;


import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Administrator
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({ServerProperties.class})
@Import({WebMvcAutoConfiguration.class})
@ComponentScan(
        value = "com.mihe",
        includeFilters = {
                @ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class)
        })
public class WebMvcConfiguration implements WebMvcConfigurer {

    /**
     * +对于header中的中文字进行解码
     *
     * @return 转换结果
     */
    @Bean
    public StringDecoderForHeaderConverter stringHeaderConverter(ServerProperties serverProperties) {
        return new StringDecoderForHeaderConverter(serverProperties.getServlet().getEncoding().getCharset());
    }

//    /**
//     * LocalDateTime时间格式化处理
//     *
//     */
//    @Bean(name = "mapperObject")
//    public ObjectMapper getObjectMapper() {
//        ObjectMapper om = new ObjectMapper();
//        JavaTimeModule javaTimeModule = new JavaTimeModule();
//        javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//        javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
//        javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
//        // 转换为格式化的json
//        om.enable(SerializationFeature.INDENT_OUTPUT);
//        // 如果json中有新增的字段并且是实体类类中不存在的，不报错
//        om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//        om.registerModule(javaTimeModule);
//        return om;
//    }
}
